package com.ylq.impl;

import com.ylq.dao.UsersDao;
import com.ylq.entity.PageVo;
import com.ylq.entity.Roles;
import com.ylq.entity.Users;
import com.ylq.entity.UsersDto;
import com.ylq.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersDao usersDao;


    @Override
    public Users login(String un, String pwd) {
        return usersDao.login(un, pwd);
    }

    @Override
    public List<Roles> getRolesByUserName(String uname) {
        return usersDao.getRolesByUserName(uname);
    }

    @Override
    public int createUser(Users users) {
        SimpleDateFormat sdf = new SimpleDateFormat();//格式化当前时间
        sdf.applyPattern("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        users.setLastLoginTime(sdf.format(date));
        users.setCreateTime(sdf.format(date));
        UUID uuid = UUID.randomUUID();
        users.setId(uuid.toString());
        return usersDao.createUser(users);
    }

    @Override
    public int updateUser(Users users) {
        return usersDao.updateUser(users);
    }

    @Override
    public int resetPassword(Users users) {
        return usersDao.resetPassword(users);
    }

    @Override
    public int lockUser(Users users) {
        return usersDao.lockUser(users);
    }

    @Override
    public int unLockUser(Users users) {
        return usersDao.unLockUser(users);
    }

    @Override
    public Users getUserByName(String loginName) {
        return usersDao.getUserByName(loginName);
    }

    @Override
    public int deleteUser(String uid) {
        return usersDao.deleteUser(uid);
    }

    @Override
    public List<Users> getUsersLayUI(UsersDto dto) {
        return usersDao.getUsersLayUI(dto);
    }

    @Override
    public Users findById(String uId) {
        return usersDao.findById(uId);
    }


}
